package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.dto.MessageDto;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import com.itheima.vto.OrderVto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class orderController {
    @Autowired
    private OrderService orderService;

    /**
     * 根据预约id查询预约信息
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public Result findById(Integer id){
        OrderVto order = orderService.findById(id);
        return  new Result(order!=null?true:false,order!=null? MessageConstant.QUERY_ORDER_SUCCESS:MessageConstant.QUERY_ORDER_FAIL,order);
    }

    /**
     * 客户端预约
     * @param messageDto
     * @return
     */
    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestBody MessageDto messageDto){
        String temp = orderService.order(messageDto);
        if(temp==MessageConstant.ORDER_SUCCESS)
            return new Result(true,temp);
        else
            return new Result(false,temp);
    }
}
